package com.scoresystem.dao.proxy;

import java.sql.Connection;

import com.scoresystem.dao.IUserDao;
import com.scoresystem.dao.impl.UserDaoImpl;
import com.scoresystem.exception.UserRepeatException;
import com.scoresystem.model.User;
import com.scoresystem.utils.JdbcUtil;
/**
 * 静态代理类，对上层调用程序只提供代理层，屏蔽具体的sql语句实现
 * @author Administrator
 *
 */
public class UserDaoProxy implements IUserDao {
	private IUserDao dao=null;
	private Connection conn=null;
	
	public UserDaoProxy()throws Exception{
		conn=JdbcUtil.getInstance().getConnection();
		dao=new UserDaoImpl(conn);
	}
	
	@Override
	public User findByName(String name)throws UserRepeatException {
		User user=dao.findByName(name);
		JdbcUtil.getInstance().free(conn);
		return user;
	}

	@Override
	public User findByUsername(String username)throws UserRepeatException {
		User user=dao.findByUsername(username);
		JdbcUtil.getInstance().free(conn);
		return user;
	}

	@Override
	public boolean add(User user) {
		boolean bool=dao.add(user);
		JdbcUtil.getInstance().free(conn);
		return bool;
	}

	@Override
	public boolean deleteUsers(String[] username) {
		boolean bool=dao.deleteUsers(username);
		JdbcUtil.getInstance().free(conn);
		return bool;
	}

	@Override
	public User findByNamePsd(String username, String password) {
		User user=dao.findByNamePsd(username, password);
		JdbcUtil.getInstance().free(conn);
		return user;
	}

	@Override
	public boolean modify(User user) {
		boolean bool=dao.modify(user);
		JdbcUtil.getInstance().free(conn);
		return bool;
	}

}
